/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DTO;

import java.awt.image.BufferedImage;
import java.io.*;
import java.net.*;
import javax.swing.JFrame;
/**
 *
 * @author Trung
 */

public class Client {
    private InetAddress ip;
    //private String ip;
    private String username;
    private String pass;
    
    private Socket sk;
    private final int PORT = 3001;
    JFrame jrame = new JFrame();


    public Client()
    {
        sk = new Socket();

    }
    
    public void Connect(String serverIP)
    {
        try
        {
            sk = new Socket(serverIP, PORT);
            
            InputStream is = getSk().getInputStream();
            OutputStream os = getSk().getOutputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            BufferedWriter bw = new BufferedWriter( new OutputStreamWriter(os));
            ObjectInputStream ois = new ObjectInputStream(is);
            //ObjectOutputStream myOos = new ObjectOutputStream();
            
            //String ipString = ip.toString();
            //String ipString = sk.getLocalAddress().toString();
            
            //bw.write(ipString + "\n");        
            //bw.flush();
            bw.write(username + "\n");
            bw.flush();
            bw.write(pass + "\n");
            bw.flush();
            bw.close();
            br.close();
            
            //Nhan Screen Image tu Server
//            while(true)
//            {
//                try{
//                     
//                }
//                catch(ClassNotFoundException ex)
//                {
//                    System.out.println(ex.getMessage());
//                }
//               
//            }
        }
        catch(UnknownHostException ex)
        {
            System.out.println(ex.getMessage());
        }
        catch(IOException ex)
        {
            System.out.println(ex.getMessage());
        }
        
    }
    
    
    /**
     * @return the name
     */
    public String getUserName() {
        return username;
    }

    /**
     * @param name the name to set
     */
    public void setUserName(String name) {
        this.username = name;
    }

    /**
     * @return the pass
     */
    public String getPass() {
        return pass;
    }

    /**
     * @param pass the pass to set
     */
    public void setPass(String pass) {
        this.pass = pass;
    }

    /**
     * @return the ip
     */
//    public String getIp() {
//        return ip;
//    }

    /**
     * @param ip the ip to set
     */
//    public void setIp(String ip) {
//        this.ip = ip;
//    }

    /**
     * @return the sk
     */
    public Socket getSk() {
        return sk;
    }

    /**
     * @param sk the sk to set
     */
    public void setSk(Socket sk) {
        this.sk = sk;
    }

    /**
     * @return the ip
     */
    public InetAddress getIp() {
        return ip;
    }

    /**
     * @param ip the ip to set
     */
    public void setIp(InetAddress ip) {
        this.ip = ip;
    }
    
}
